package com.clean.cleantotal.compores

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import com.blankj.utilcode.util.SPUtils
import com.clean.cleantotal.R
import com.clean.cleantotal.base.BaseFragment
import com.clean.cleantotal.bean.DataUtils
import com.clean.cleantotal.bean.MineBean
import com.clean.cleantotal.compores.clean.NewCleanScanActivity
import com.clean.cleantotal.databinding.FragmentMineBinding
import com.clean.cleantotal.utils.FormatterSize
import com.clean.cleantotal.utils.Utils
import com.drake.brv.utils.linear
import com.drake.brv.utils.setup


/**
 * 我的
 */
class MineFragment : BaseFragment<FragmentMineBinding>() {
    override fun getViewBinding(
        inflater: LayoutInflater, container: ViewGroup?
    ): FragmentMineBinding {
        return FragmentMineBinding.inflate(layoutInflater, container, false)
    }

    override fun initView() {
        val cleanTotalSize = SPUtils.getInstance().getLong("cleanTotalSize", 0L)
        mBinding.tvSize.text = FormatterSize.formatFileSize(context, cleanTotalSize)
        mBinding.recyclerView.linear().setup {
            addType<MineBean> { R.layout.item_mine_layout }
            onClick(R.id.mineLayout) {
                when (getModel<MineBean>().type) {
                    1 -> {
                        // 隐私协议
                        Utils.openPolicy(context)
                    }
                }
            }
        }.models = DataUtils.getMine()
        mBinding.ivCleanUp.setOnClickListener {
            context?.let {
                Utils.requestPr(it) {
                    openActivity(NewCleanScanActivity::class.java)
                }
            }
        }
    }

    override fun initData(savedInstanceState: Bundle?) {
    }

}